package com.hs.srm.admin.modules.sampletest.controller;

import com.hs.srm.admin.modules.sampletest.service.ExamineGoodsService;
import com.hs.srm.admin.modules.orders.entity.StockEntity;
import com.hs.srm.admin.modules.sys.controller.AbstractController;
import com.hs.srm.base.common.annotation.SysLog;
import com.hs.srm.common.utils.PageUtils;
import com.hs.srm.common.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 *
 * @Description: 品管验货
 * @Author yangch
 * @Date 2019/6/28
 *
 */
@RestController
@RequestMapping("/examineGoods")
public class ExamineGoodsController  extends AbstractController {

    /**
     * @Description: 注入业务层
     */
    @Autowired
    private ExamineGoodsService examineGoodsService;

    /**
     * @Description: 货物查询
     */
    @ResponseBody
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        // 物料库存数据
        PageUtils page = examineGoodsService.queryPage(params);
        return R.ok(page);
    }

    /**
     * 验货，将status改成4
     */
    @SysLog("验货")
    @RequestMapping("/changeStatus")
    @RequiresPermissions("inquiry:submit")
    public R submit(@RequestParam(value = "pkId[]") String[] pkId) {
        if (pkId == null || pkId.length == 0) {
            return R.error();
        }
        List<String> idList = Arrays.asList(pkId);
        List<StockEntity> stockEntityList = this.examineGoodsService.selectBatchIds(idList);
        stockEntityList.forEach(x ->{
            x.setStatus(4);
        });
        this.examineGoodsService.updateBatchById(stockEntityList);
        return R.ok();
    }

}
